package com.example.huwang.activity;

import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.huwang.R;
import com.example.huwang.app.MainApplication;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.BindView;
import butterknife.ButterKnife;

public class UserInfoActivity extends BaseActivity {
    @BindView(R.id.icon_user)
    public ImageView iconUser;
    @BindView(R.id.user_name)
    public TextView userName;
    @BindView(R.id.user_phone)
    public TextView userPhone;
    @BindView(R.id.reset_psw)
    public RelativeLayout resetPsw;
    @BindView(R.id.add_blacklist)
    public RelativeLayout addBlacklist;
    @BindView(R.id.history_list)
    public RelativeLayout historyList;

    private static int RESULT_LOAD_IMAGE = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info);
        //绑定初始化ButterKnife
        ButterKnife.bind(this);
        initview();
    }

    private void initview() {
        userName.setText("超级用户");
        userPhone.setText("手机号：" + MainApplication.PHONE);
        iconUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                if (intent.resolveActivity(getPackageManager()) != null) {
                    startActivityForResult(intent, RESULT_LOAD_IMAGE);
                }
            }
        });
        resetPsw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        addBlacklist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserInfoActivity.this, AddBlacklistActivity.class);
                startActivity(intent);
            }
        });
        historyList.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserInfoActivity.this, HistoryActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RESULT_LOAD_IMAGE) {
            if (data != null) {
                Uri uri = data.getData();
                iconUser.setImageURI(uri);
            }
        }
    }
}
